#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
using namespace std;
const int N = 20;
int cnt[N];
int T, n;
int main()
{
    cin >> T;
    while (T--)
    {
        cin >> n;
        memset(cnt, 0, sizeof cnt);
        int sum = 0, x = 0;
        for (int i = 0; i < n; i++)
        {
            cin >> x;
            sum ^= x;
            for (int j = 0; j < N; j++)
            {
                cnt[j] += x >> j & 1;
            }
        }
        if (sum == 0)
        {
            cout << "0" << endl;
            continue;
        }
        for (int i = N - 1; i >= 0; i--)
        {
            if (sum >> i & 1)
            {
                if (cnt[i] == 1) cout << "1" << endl;
                else if (n % 2) cout << "1" << endl;
                else cout << "-1" << endl;
                break;
            }
        }
    }
    return 0;
}